package com.chatcompetition.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chatcompetition.domain.entity.UmsMenu;
import com.chatcompetition.mapper.UmsMenuMapper;

import com.chatcompetition.service.UmsMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class UmsMenuServiceImpl implements UmsMenuService {

    @Autowired
    private UmsMenuMapper umsMenuMapper;

    @Override
    public List<String> getMenuTitlesByLevel(int level) {
        // 使用 MyBatis-Plus 的 QueryWrapper 构建查询条件
        QueryWrapper<UmsMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("level", level); // 查询 level 等于指定值的记录

        // 查询所有符合条件的菜单
        List<UmsMenu> menus = umsMenuMapper.selectList(queryWrapper);

        // 提取菜单的 title 字段
        return menus.stream()
                .map(UmsMenu::getTitle)
                .collect(Collectors.toList());
    }
}